/*********************************************************************************************************
 *  ------------------------------------------------------------------------------------------------------
 *  file description
 *  ------------------------------------------------------------------------------------------------------
 *         \file  crc.h
 *         \unit  crc
 *        \brief  This is a C language version of commonly used crc algorithms
 *       \author  Lamdonn
 *      \version  v1.0.0
 *      \license  GPL-2.0
 *    \copyright  Copyright (C) 2023 Lamdonn.
 ********************************************************************************************************/
#ifndef __crc_H
#define __crc_H


#define CRC_OPT_EN      0
#define CRC_STD_EN      0
#define CRC_TAB_EN      0


#if CRC_OPT_EN

typedef enum
{
    CRC4_ITU=0,
    CRC5_EPC,
    CRC5_ITU,
    CRC5_USB,
    CRC6_ITU,
    CRC7_MMC,
    CRC8,
    CRC8_ITU,
    CRC8_ROHC,
    CRC8_MAXIM,
    CRC16_IBM,
    CRC16_MAXIM,
    CRC16_USB,
    CRC16_MODBUS,
    CRC16_CCITT,
    CRC16_CCITT_FALSE,
    CRC16_X25,
    CRC16_XMODEM,
    CRC16_DNP,
    CRC32,
    CRC32_MPEG_2,
    CRC_MAX,
}E_CRC_OPT;

/* Custom universal model, within 32 bits, any customization is possible */
unsigned int crc(const unsigned char* data, unsigned int len, E_CRC_OPT type);
#endif

#if CRC_STD_EN
/* Standard reference model */

unsigned char crc4_itu(const unsigned char* data, unsigned int len);
unsigned char crc5_epc(const unsigned char* data, unsigned int len);
unsigned char crc5_itu(const unsigned char* data, unsigned int len);
unsigned char crc5_usb(const unsigned char* data, unsigned int len);
unsigned char crc6_itu(const unsigned char* data, unsigned int len);
unsigned char crc7_mmc(const unsigned char* data, unsigned int len);
unsigned char crc8(const unsigned char* data, unsigned int len);
unsigned char crc8_itu(const unsigned char* data, unsigned int len);
unsigned char crc8_rohc(const unsigned char* data, unsigned int len);
unsigned char crc8_maxim(const unsigned char* data, unsigned int len);
unsigned short int crc16_ibm(const unsigned char* data, unsigned int len);
unsigned short int crc16_maxim(const unsigned char* data, unsigned int len);
unsigned short int crc16_usb(const unsigned char* data, unsigned int len);
unsigned short int crc16_modbus(const unsigned char* data, unsigned int len);
unsigned short int crc16_ccitt(const unsigned char* data, unsigned int len);
unsigned short int crc16_ccitt_false(const unsigned char* data, unsigned int len);
unsigned short int crc16_x25(const unsigned char* data, unsigned int len);
unsigned short int crc16_xmodem(const unsigned char* data, unsigned int len);
unsigned short int crc16_dnp(const unsigned char* data, unsigned int len);
unsigned int crc32(const unsigned char* data, unsigned int len);
unsigned int crc32_mpeg_2(const unsigned char* data, unsigned int len);
#endif

#if CRC_TAB_EN
unsigned char crc8_tab(const unsigned char* data, unsigned int length);
unsigned char crc8_tab_itu(const unsigned char* data, unsigned int length);
unsigned char crc8_tab_rohc(const unsigned char* data, unsigned int length);
unsigned char crc8_tab_maxim(const unsigned char* data, unsigned int length);
unsigned short int crc16_tab_ibm(const unsigned char* data, unsigned int length);
unsigned short int crc16_tab_maxim(const unsigned char* data, unsigned int length);
unsigned short int crc16_tab_usb(const unsigned char* data, unsigned int length);
unsigned short int crc16_tab_modbus(const unsigned char* data, unsigned int length);
unsigned short int crc16_tab_ccitt(const unsigned char* data, unsigned int length);
unsigned short int crc16_tab_ccitt_false(const unsigned char* data, unsigned int length);
unsigned short int crc16_tab_x25(const unsigned char* data, unsigned int length);
unsigned short int crc16_tab_xmodem(const unsigned char* data, unsigned int length);
unsigned int crc32_tab(const unsigned char* data, unsigned int length);
unsigned int crc32_tab_mpeg_2(const unsigned char* data, unsigned int length);
#endif

#endif
